package com.tianquan.client;

import com.tianquan.client.loadBalan.BlockingLoadBalancerClient;
import com.tianquan.client.loadBalan.strategy.LoadBalancerEnum;
import com.tianquan.common.instance.ServiceInstance;
import lombok.extern.slf4j.Slf4j;

/**
 *@Author: tianquan
 *@date: 2024-11-03  20:29
 *@Description: 测试
 */
@Slf4j
public class Test1 {

    public static void main(String[] args) throws InterruptedException {



        PBankClient pBankClient = PBankClient.PBankClientBuilder.builder()
                .user("root")
                .password("123456")
                .address("localhost")
                .port(9850)
                .serverName("oderService")
                .build();

        new Thread(() ->{
            pBankClient.startClient();
        }).start();



        BlockingLoadBalancerClient loadBalancerClient = new BlockingLoadBalancerClient(LoadBalancerEnum.Random);
        while (true) {
            Thread.sleep(5000);
            ServiceInstance userService = loadBalancerClient.choose("userService");
            ServiceInstance oderService = loadBalancerClient.choose("oderService");
            log.debug("客户端选择userService服务 - {}", userService);
            log.debug("客户端选择oderService服务 - {}", oderService);
        }

    }
}
